In my tests, the code using the For...Each construct runs at least twice as fast:
For lngLoop = 0 To 10000
For Each oForm In Forms
strName = oForm.Name
Next
Next
This runs faster because the enumeration function keeps track of which object to retrieve when For...Each is used. However, when you access the collection using an index or a key value, a search must be performed through that collection every time you access it. This can take a while because searching through collections seems to be done sequentially.
With. . .End With
Using the With...End With construct is slightly faster than not using it. In Visual Basic 5, this construct seemed to be much faster than it does now in Visual Basic 6. Microsoft probably did some optimization underneath the hood. Heres a sample of the code where an object is declared of the type Employee, called oEmp. In the first routine, properties are set on the Employee object and then are retrieved back. In each line, the Employee object is referenced: